package com.topisv.tms.repository;


import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import com.topisv.tms.entity.EdiGoodsSku;

public interface EdiGoodsSkuDao extends PagingAndSortingRepository<EdiGoodsSku, Long>, JpaSpecificationExecutor<EdiGoodsSku>{

	/**
	 * 根据客户编码与skuxinxi获得商品信息
	 * @param customerCode  客户编码
	 * @param sku           sku信息
	 * @return
	 */
	EdiGoodsSku findByCustomerCodeAndSku(String customerCode,String sku);
	
	EdiGoodsSku findByCustomerCodeAndBar(String customerCode,String bar);
	
	EdiGoodsSku findByCustomerCodeAndSpec(String customerCode,String spec);
	
	@Modifying
	@Query("delete from EdiGoodsSku e where e.customerCode=?")
	void deleteCustomerCode(String customerCode);
	@Modifying
	@Query("delete from EdiGoodsSku e where e.customerCode=?1 and sku = ?2")
	void deleteByCustomerCodeAndSku(String customerCode,String sku);
	
	EdiGoodsSku findBySku(String sku);
	
	EdiGoodsSku findBySkuAndCustomerCode(String sku,String customerCode);
	
	@Query(nativeQuery=true, value=" SELECT a.* FROM edi_goods_sku a, edi_order_item b "
			+ " WHERE a.sku_id = b.sku_id "
			+ " AND a.customer_code = b.customer_code "
			+" AND b.ordeno = :ordeno "
			+" AND ( "
			+"		       a.is_shelf_life_mgmt = '1' "
			+"        OR a.is_batch_mgmt = '1' "
			+"	) ")
	List<Object[]> checkSKUShelf_lifeOrBatch(@Param("ordeno") String ordeno);

	
}
